package com.eva.ss.api;

import com.eva.framework.common.api.BaseController;
import com.eva.framework.common.model.ApiResponse;
import com.eva.framework.rbac.model.RbacLoginByPasswordDTO;
import com.eva.framework.rbac.trace.Trace;
import com.eva.ss.service.LoginByPasswordService;
import com.eva.ss.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Api(tags = "系统功能")
@Trace(exclude = true)
@Slf4j
@RestController
@RequestMapping("/system")
public class SystemController extends BaseController {

    @Resource
    private LoginService loginService;

    @Resource
    private LoginByPasswordService loginByPasswordService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public ApiResponse<String> login (@RequestBody RbacLoginByPasswordDTO dto, HttpServletRequest request, HttpServletResponse response) {
        return ApiResponse.success(loginByPasswordService.login(dto, request, response));
    }

    @ApiOperation("退出登录")
    @PostMapping("/logout")
    public ApiResponse<?> logout (HttpServletRequest request) {
        loginService.logout(request);
        return ApiResponse.success(null);
    }
}
